<?php
class E_books_model extends MY_Model{
	var $nid;
	var $bid;
	var $pid;
	var $language;
	var $title;
	var $format;	
	var $intro;
	var $bok_size;
	var $time;
	var $status;
	var $project_numbers;
	var $isbn;
	var $created;
	
	function __construct($id=''){
		parent::__construct();
		$GLOBALS['table'] = 'e_books';
		if($id){
			$query = $this->db->get_where('e_books',array('id' => $id),1);
			$result = $query->result();
			if(!empty($result)){
				$this->id = $result[0]->id;
				$this->nid = $result[0]->nid;
				$this->bid = $result[0]->bid;
				$this->pid = $result[0]->pid;
				$this->language = $result[0]->language;
				$this->title = $result[0]->title;
				$this->format = $result[0]->format;
				$this->intro = $result[0]->intro;
				$this->bok_size = $result[0]->bok_size;
				$this->time = $result[0]->time;
				$this->status = $result[0]->status;
				$this->project_numbers = $result[0]->project_numbers;
				$this->isbn = $result[0]->isbn;
				$this->created = $result[0]->created;
			}
		}
	}
	
	function get_all_rows($where){
		if($where['key']){
			switch($where['op']){
				case '1':
					$this->db->like('title',$where['key']);
					break;
				case '2';
					$this->db->like('isbn',$where['key']);
					break;
				case '3':
					$this->db->like('project_numbers',$where['key']);
					break;
			}
		}
		if($where['pid']){
			$this->db->where('pid',$where['pid']);
		}
		if($where['language']){
			$this->db->where('language',$where['language']);
		}
		if($where['status']){
			$this->db->where('status',$where['status']);
		}
		return $this->db->count_all_results('e_books');
	}
	
	function get_consumable_by_page($limit,$offset,$where){
		if($where['pid']){
			$this->db->where('pid',$where['pid']);
		}
		if($where['key']){
			switch($where['op']){
				case '1':
					$this->db->like('title',$where['key']);
					break;
				case '2';
					$this->db->like('isbn',$where['key']);
					break;
				case '3':
					$this->db->like('project_numbers',$where['key']);
					break;
			}
		}
		
		if($where['language']){
			$this->db->where('language',$where['language']);
		}
		if($where['status']){
			$this->db->where('status',$where['status']);
		}
		$query = $this->db->get('e_books',$limit,$offset);
		return $query->result_array();
	}
}